package mysql

import "gorm.io/gorm"

type Order struct {
	gorm.Model
	UserId   int64   `gorm:"type:int" json:"user_id"`
	OrderSn  string  `gorm:"type:varchar(100);unique;" json:"order_sn"`
	Price    float64 `gorm:"type:decimal(10,2);" json:"price"`
	CourseId int64   `gorm:"type:int" json:"course_id"`
	Status   int64   `gorm:"type:int;default:1;" json:"status"` //1待支付 2已支付 3已取消
}

func (o *Order) CreateOrder(orderSn string, price float64, courseId int64, userId int64) error {
	or := &Order{
		UserId:   userId,
		OrderSn:  orderSn,
		Price:    price,
		CourseId: courseId,
	}
	err := DB.Create(&or).Error
	if err != nil {
		return err
	}
	return nil
}
